package com.senmin.aPrinciple.a3DependenceInversionPrinciple.tdemo1;

/**
 * @className: demeter1
 * @author: xpj
 * @create: 2021/6/5
 * @description: 案例：请编写完成person消息的功能【用依赖倒置】 方式1：通过接口来实现依赖
 */
public class demo1 {
    public static void main(String[] args) {
        Changhong changhong = new Changhong();
        OpenAndClose  openAndClose =  new OpenAndClose();
        openAndClose.open(changhong);
    }
}

//方式1通过接口来实现依赖
interface IOpenAndClose {
    public void open (ITV tv);//抽象方法，接收接口
}

interface ITV{
    public void play();
}

class Changhong implements ITV{
    @Override
    public void play(){
        System.out.println("打开长虹电视打开");
    }
}

//实现接口
class OpenAndClose implements  IOpenAndClose{
    @Override
    public  void open(ITV tv){
        tv.play();
    }
}


